package com.rundatop.core.util;

import java.util.Random;

public class CodeUtil {

	public static int random(){
        int[] array = {0,1,2,3,4,5,6,7,8,9};
        Random rand = new Random();
        for (int i = 10; i > 1; i--) {
            int index = rand.nextInt(i);
            int tmp = array[index];
            array[index] = array[i - 1];
            array[i - 1] = tmp;
        }
        int result = 0;
        for(int i = 0; i < 6; i++)
            result = result * 10 + array[i];
        return result;
    }
	
	/**
	 * 生成指定长度随机数
	 * @param length 长度
	 * 
	 * **/
	public static String getRandom(int length) {
		String result = "";
		// 下面的6改成8就是8位随机数字
		while (result.length() < length) {
			String str = String.valueOf((int) (Math.random() * 10));
			if (result.indexOf(str) == -1) {
				result += str;
			}
		}
		return result;
	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 50; i++) {
			System.out.println(getRandom(6));
		}
		for (int i = 0; i < 50; i++) {
			System.out.println(getRandom(8));
		}
		  
	}
}
